package model;

/**
 * @author samuel
 *
 */
public class Time {
    




	private int timeInMicroSecond;
	private static double MICRO_TO_SEC = Math.pow(10, -6);
	private static double MICRO_TO_MILI_SEC=Math.pow(10, -3);
	private Time(int timeInMicroSecond) {
		this.timeInMicroSecond = timeInMicroSecond;
	}

	/**
	 * @param second
	 * @return
	 */
	public static Time makeTimeFromSecond(int second)
	{
		int micro = (int)(second/MICRO_TO_SEC);
		return new Time(micro);
	}
	
	/**
	 * @param second
	 * @return
	 */
	public static Time makeTimeFromSecond(float second)
	{
		int micro = (int)(second/MICRO_TO_SEC);
		return new Time(micro);
	}
	
	/**
	 * @param milisecond
	 * @return
	 */
	public static Time makeTimeFromMiliSecond(int milisecond)
	{
		int micro = (int)(milisecond/MICRO_TO_MILI_SEC);
		return new Time(micro);
	}
	
	/**
	 * @param milisecond
	 * @return
	 */
	public static Time makeTimeFromMiliSecond(float milisecond)
	{
		int micro = (int)(milisecond/MICRO_TO_MILI_SEC);
		return new Time(micro);
	}
	
	/**
	 * @return
	 */
	public int getTimeInMicroSecond()
	{
		return timeInMicroSecond;
	}
	
    /**
     * @return
     */
    public int getFloredTimeInSecond()
    {
    	return (int) Math.floor(getTimeInSecond());
    }



	/**
	 * @param time
	 * @return 
	 */
	public Time addTime(Time time) {
		int sumOfMicroSecond = time.getTimeInMicroSecond()+this.getTimeInMicroSecond();
		return new Time(sumOfMicroSecond);
	}
	           
	/**
	 * @return
	 */
	public int getFloredTimeInMiliSecond() {
	
	   	return (int) Math.floor(timeInMicroSecond*MICRO_TO_MILI_SEC);
	}

	public double getTimeInSecond() {
		return timeInMicroSecond*MICRO_TO_SEC;
	}
	
	/**
	 * @param time
	 * @return
	 */
	public int compare(Time time) {
	    if(time.getTimeInMicroSecond()>this.getTimeInMicroSecond())
	    {
	    	return -1;
	    }
	    else if(time.getTimeInMicroSecond() == this.getTimeInMicroSecond())
	    {
	    	return 0;
	    }
	    else
	    	return 1;
	    	
		
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Time other = (Time) obj;
		if (timeInMicroSecond != other.timeInMicroSecond)
			return false;
		return true;
	}
}
